package Greed;

import java.util.Arrays;

//无重叠区间
public class NonOverlappingIntervals {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals,(v1,v2)->{
            return v1[0]-v2[0];
        });
        int left=intervals[0][0];
        int right=intervals[0][1];
        int count=0;
        for (int i = 1; i < intervals.length ; i++) {
            int a=intervals[i][0];
            int b=intervals[i][1];
            if(a<right){
                right=Math.min(right,b);
                count++;
            }else {
                right=b;
            }
        }
        return count;
    }
}
